﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface; 


namespace MaxStudio.Concrete.Server.Service
{
    public class RMVenderService : ServiceHandle, IRMVender
    {
        #region IRMVender Members

        public OperationResult<List<tb_RMVender>> GetAllRMVender()
        {
            ConcreteDaoDataContext dataContext = new ConcreteDaoDataContext();

            OperationResult<List<tb_RMVender>> result = new OperationResult<List<tb_RMVender>>();
            List<tb_RMVender> list = new List<tb_RMVender>();
            try
            {
                list = dataContext.GetAllRMVender();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
            
        }

        public OperationResult<tb_RMVender> GetRMVenderById(int id)
        {
            ConcreteDaoDataContext dataContext = new ConcreteDaoDataContext();

            OperationResult<tb_RMVender> result = new OperationResult<tb_RMVender>();
            tb_RMVender rMVender;
            try
            {
                rMVender = dataContext.GetRMVenderById(id);
                if (rMVender == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = rMVender;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RMVender> CreateRMVender(tb_RMVender entity)
        {
            OperationResult<tb_RMVender> result = new OperationResult<tb_RMVender>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.CreateRMVender(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RMVender> ModifyRMVender(tb_RMVender entity)
        {
            OperationResult<tb_RMVender> result = new OperationResult<tb_RMVender>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.ModifyRMVender(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RMVender> DeleteRMVender(tb_RMVender entity)
        {
            OperationResult<tb_RMVender> result = new OperationResult<tb_RMVender>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.DeleteRMVender (entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
